#include "NetAwaiter.h"
#include "coroutine.h"
using namespace CCoroutine;
NetAwaiter::NetAwaiter(QNetworkReply *reply)
{
    this->reply = reply;
}
NetAwaiter::~NetAwaiter(){
    QObject::disconnect(con);
}
bool NetAwaiter::ready()
{
    return reply->isFinished();
}

void NetAwaiter::suspend(PromiseBase *ctx)
{
    con = QObject::connect(reply,&QNetworkReply::finished,[=](){
        QObject::disconnect(con);
        ctx->resume();
    });
}

void NetAwaiter::resume()
{

}

AwaiterBase *getAwaiter(QNetworkReply *timer)
{
    return new NetAwaiter(timer);
}

AwaiterBase *getAwaiter(QNetworkReply &timer)
{
    return new NetAwaiter(&timer);
}
